home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 45CW5I (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  5.4 KB  |  170 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.JButton;
  4. import com.sun.java.swing.JComponent;
  5. import com.sun.java.swing.UIManager;
  6. import com.sun.java.swing.plaf.ComponentUI;
  7. import com.sun.java.swing.plaf.UIResource;
  8. import com.sun.java.swing.plaf.basic.BasicScrollBarUI;
  9. import java.awt.Color;
  10. import java.awt.Component;
  11. import java.awt.Dimension;
  12. import java.awt.Graphics;
  13. import java.awt.Rectangle;
  14.  
  15. public class MetalScrollBarUI extends BasicScrollBarUI {
  16.    private static Color shadowColor;
  17.    private static Color highlightColor;
  18.    private static Color thumbColor;
  19.    private static Color thumbShadow;
  20.    private static Color thumbHighlightColor;
  21.    protected MetalBumps bumps;
  22.    protected MetalScrollButton increaseButton;
  23.    protected MetalScrollButton decreaseButton;
  24.    protected static int scrollBarWidth;
  25.    protected ScrollBarListener scrollBarListener = new ScrollBarListener(this);
  26.    public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding";
  27.    protected boolean isFreeStanding = true;
  28.  
  29.    protected void configureScrollBarColors() {
  30.       shadowColor = UIManager.getColor("ScrollBar.shadow");
  31.       highlightColor = UIManager.getColor("ScrollBar.highlight");
  32.       thumbColor = UIManager.getColor("ScrollBar.thumb");
  33.       thumbShadow = UIManager.getColor("ScrollBar.thumbShadow");
  34.       thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
  35.    }
  36.  
  37.    protected JButton createDecreaseButton(int orientation) {
  38.       this.decreaseButton = new MetalScrollButton(orientation, scrollBarWidth, this.isFreeStanding);
  39.       return this.decreaseButton;
  40.    }
  41.  
  42.    protected JButton createIncreaseButton(int orientation) {
  43.       this.increaseButton = new MetalScrollButton(orientation, scrollBarWidth, this.isFreeStanding);
  44.       return this.increaseButton;
  45.    }
  46.  
  47.    public static ComponentUI createUI(JComponent c) {
  48.       return new MetalScrollBarUI();
  49.    }
  50.  
  51.    protected Dimension getMinimumThumbSize() {
  52.       return new Dimension(scrollBarWidth, scrollBarWidth);
  53.    }
  54.  
  55.    public Dimension getPreferredSize(JComponent c) {
  56.       return super.scrollbar.getOrientation() == 1 ? new Dimension(scrollBarWidth, scrollBarWidth * 3 + 10) : new Dimension(scrollBarWidth * 3 + 10, scrollBarWidth);
  57.    }
  58.  
  59.    public void installUI(JComponent c) {
  60.       scrollBarWidth = (Integer)UIManager.get("ScrollBar.width");
  61.       if (((Component)c).getBackground() == null || ((Component)c).getBackground() instanceof UIResource) {
  62.          ((Component)c).setBackground(UIManager.getColor("ScrollBar.background"));
  63.       }
  64.  
  65.       super.installUI(c);
  66.       this.bumps = new MetalBumps(10, 10, thumbHighlightColor, thumbShadow, thumbColor);
  67.       c.addPropertyChangeListener(this.scrollBarListener);
  68.       this.scrollBarListener.handlePropertyChange(c.getClientProperty("JScrollBar.isFreeStanding"));
  69.    }
  70.  
  71.    protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
  72.       if (((Component)c).isEnabled()) {
  73.          g.translate(thumbBounds.x, thumbBounds.y);
  74.          if (super.scrollbar.getOrientation() == 1) {
  75.             if (!this.isFreeStanding) {
  76.                thumbBounds.width += 2;
  77.             }
  78.  
  79.             g.setColor(thumbColor);
  80.             g.fillRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
  81.             g.setColor(thumbShadow);
  82.             g.drawRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
  83.             g.setColor(thumbHighlightColor);
  84.             g.drawLine(1, 1, thumbBounds.width - 3, 1);
  85.             g.drawLine(1, 1, 1, thumbBounds.height - 2);
  86.             this.bumps.setBumpArea(thumbBounds.width - 6, thumbBounds.height - 7);
  87.             this.bumps.paintIcon(c, g, 3, 4);
  88.             if (!this.isFreeStanding) {
  89.                thumbBounds.width -= 2;
  90.             }
  91.          } else {
  92.             if (!this.isFreeStanding) {
  93.                thumbBounds.height += 2;
  94.             }
  95.  
  96.             g.setColor(thumbColor);
  97.             g.fillRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
  98.             g.setColor(thumbShadow);
  99.             g.drawRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
  100.             g.setColor(thumbHighlightColor);
  101.             g.drawLine(1, 1, thumbBounds.width - 3, 1);
  102.             g.drawLine(1, 1, 1, thumbBounds.height - 3);
  103.             this.bumps.setBumpArea(thumbBounds.width - 7, thumbBounds.height - 6);
  104.             this.bumps.paintIcon(c, g, 4, 3);
  105.             if (!this.isFreeStanding) {
  106.                thumbBounds.height -= 2;
  107.             }
  108.          }
  109.  
  110.          g.translate(-thumbBounds.x, -thumbBounds.y);
  111.       }
  112.    }
  113.  
  114.    protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
  115.       g.translate(trackBounds.x, trackBounds.y);
  116.       if (super.scrollbar.getOrientation() == 1) {
  117.          if (!this.isFreeStanding) {
  118.             trackBounds.width += 2;
  119.          }
  120.  
  121.          if (((Component)c).isEnabled()) {
  122.             g.setColor(shadowColor);
  123.             g.drawLine(0, 0, 0, trackBounds.height - 1);
  124.             g.drawLine(trackBounds.width - 2, 0, trackBounds.width - 2, trackBounds.height - 1);
  125.             g.drawLine(2, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1);
  126.             g.drawLine(2, 0, trackBounds.width - 2, 0);
  127.             g.setColor(highlightColor);
  128.             g.drawLine(1, 1, 1, trackBounds.height - 2);
  129.             g.drawLine(1, 1, trackBounds.width - 3, 1);
  130.             g.drawLine(trackBounds.width - 1, 0, trackBounds.width - 1, trackBounds.height - 1);
  131.          } else {
  132.             MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height);
  133.          }
  134.  
  135.          if (!this.isFreeStanding) {
  136.             trackBounds.width -= 2;
  137.          }
  138.       } else {
  139.          if (!this.isFreeStanding) {
  140.             trackBounds.height += 2;
  141.          }
  142.  
  143.          if (((Component)c).isEnabled()) {
  144.             g.setColor(shadowColor);
  145.             g.drawLine(0, 0, trackBounds.width - 1, 0);
  146.             g.drawLine(0, 2, 0, trackBounds.height - 2);
  147.             g.drawLine(0, trackBounds.height - 2, trackBounds.width - 1, trackBounds.height - 2);
  148.             g.drawLine(trackBounds.width - 1, 2, trackBounds.width - 1, trackBounds.height - 1);
  149.             g.setColor(highlightColor);
  150.             g.drawLine(1, 1, trackBounds.width - 2, 1);
  151.             g.drawLine(1, 1, 1, trackBounds.height - 3);
  152.             g.drawLine(0, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1);
  153.          } else {
  154.             MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height);
  155.          }
  156.  
  157.          if (!this.isFreeStanding) {
  158.             trackBounds.height -= 2;
  159.          }
  160.       }
  161.  
  162.       g.translate(-trackBounds.x, -trackBounds.y);
  163.    }
  164.  
  165.    public void uninstallUI(JComponent c) {
  166.       super.uninstallUI(c);
  167.       c.removePropertyChangeListener(this.scrollBarListener);
  168.    }
  169. }
  170.